﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;

namespace OINS_VS08
{
    class Client2
    {
        private int BufferSize = 256;
        private NetworkStream streamToServer;

        public Client2()
        {
            string serverName = "localhost";
            Console.WriteLine("Polaczenie z {0}", serverName);
            TcpClient tcpSocket = new TcpClient("127.0.0.1", 65000);
            streamToServer = tcpSocket.GetStream();
            
        }
        public void Run()
        {
            String response;
            
            System.IO.StreamWriter writer = new System.IO.StreamWriter(streamToServer);
            System.IO.StreamReader Reader = new System.IO.StreamReader(streamToServer);
            writer.WriteLine("Hello aP2P Server");
            writer.Flush();
            response=Reader.ReadLine();
            if (response == "Hello aP2P Client")
            {
                System.Console.WriteLine("polaczenie nawiazane");
               

                // a = System.Console.ReadLine();

                /// a = System.Console.ReadLine();
                 System.Console.WriteLine("wpisz komende");
                 System.Console.ReadLine(); ;
                  String a = System.Console.ReadLine();
                  System.Console.WriteLine(a);
                writer.WriteLine(a);
                writer.Flush();
                System.Console.WriteLine("a tu nie jestem tu");
            }
            

            response = Reader.ReadLine();
            if (response == "Podaj nazwe pliku lub jego typ")
            {
                System.Console.WriteLine("podaj nazwe pliku");
                String argument = System.Console.ReadLine();
                //argument = System.Console.ReadLine();
                writer.WriteLine(argument);
                System.Console.WriteLine("ariwa ariwa");
                writer.Flush();
                
            }


            
           







          //  writer.Flush();

        /*    bool fQuit = false;

            while (!fQuit)
            {
                char[] buffer = new char[BufferSize];
                System.IO.StreamReader reader = new System.IO.StreamReader(streamToServer);

                int bytesRead = reader.Read(buffer, 0, BufferSize);

                if (bytesRead == 0)
                    fQuit = true;
                else
                {
                    string theString = new String(buffer);
                    Console.WriteLine(theString);
                }
            }   */
            streamToServer.Close();
            //return 0;
        }
    }
}

